package best.driver.android.common.utils;


import android.content.Context;
import best.driver.android.common.app.AppProxyFactory;

public class DisplayUtils {

    /**
     * 根据手机的分辨率从 dip 的单位 转成为 px(像素)
     */
    public static int dipToPixel(float dpValue) {
        Context context = AppProxyFactory.getProxy().getContext();
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dip
     */
    public static int pixelToDip(float pxValue) {
        Context context = AppProxyFactory.getProxy().getContext();
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    public static int getScreenWidth() {
        Context context = AppProxyFactory.getProxy().getContext();
        return context.getResources().getDisplayMetrics().widthPixels;
    }

    public static int getScreenHeight() {
        Context context = AppProxyFactory.getProxy().getContext();
        return context.getResources().getDisplayMetrics().heightPixels;
    }
}
